
* estimate model

*Original model specification from Beardsley (2011, p. 210, Model 2 in Table 5.1)
use book-basedata-replication, clear
eststo clear
eststo, title(original): stcox manip2 manip2_t nomanip2 nomanip2_t prevcris2 viol2 crisdur2 jointdem victory2 contig2 prevcris2_t viol2_t crisdur2_t jointdem_t victory2_t contig2_t if _t<3650, strata(order5) cluster(dyadno) efron nohr


*evaluate proportional hazards assumption --> VIOLATED
estat phtest, detail

*is it a problem with stsplit (see Jin/Boehmke 2017)? -->looks like it, coefficients are different with the adequate procedure in Stata
stcox manip2 nomanip2 prevcris2 viol2 crisdur2 jointdem victory2 contig2  if _t<3650, strata(order5) cluster(dyadno) efron nohr texp(_t) tvc(manip2 nomanip2 prevcris2 viol2 crisdur2 jointdem victory2 contig2)


*In order to be sure, I use the manual work around with the stsplit command
stsplit, at(failures)

*recalculate the interaction with time
foreach var in manip2 nomanip2 prevcris2 viol2 crisdur2 jointdem victory2 contig2 {
replace `var'_t= `var'*_t
}

*rerun with correctly split variables ->save results for table
eststo, title(after split): stcox manip2 manip2_t nomanip2 nomanip2_t prevcris2 viol2 crisdur2 jointdem victory2 contig2 prevcris2_t viol2_t crisdur2_t jointdem_t victory2_t contig2_t if _t<3650, strata(order5) cluster(dyadno) efron nohr

*evaluate proportional hazards assumption --> VIOLATED for manip2
estat phtest, detail

*rerun without interactions
stcox manip2 nomanip2 prevcris2 viol2 crisdur2 jointdem victory2 contig2 if _t<3650, strata(order5) cluster(dyadno) efron nohr

*evaluate proportional hazards assumption --> VIOLATED for manip2 and prevcris2
estat phtest, detail

*rerun -- add interaction with manip2 and prevcris2  ->save results for table
eststo, title(restricted): stcox manip2 manip2_t nomanip2 prevcris2 prevcris2_t viol2 crisdur2 jointdem victory2 contig2 if _t<3650, strata(order5) cluster(dyadno) efron nohr

*evaluate proportional hazards assumption --> PERFECT
estat phtest, detail

esttab, star(* 0.1 ** 0.05 *** 0.01) b(3) se(3)  mtitle nodepvar  /*
*/ 		order(manip2 manip2_t nomanip2 nomanip2_t) noobs /*
*/		scalar("N_sub Cases" "N_fail Failures") /*
*/ 		varlabels(manip2 "Manipulation"/*
*/ 		manip2_t "Manipulation * time"/*
*/		nomanip2 "Other mediation "/*
*/ 		nomanip2_t "Other mediation * time"/*
*/ 		prevcris2 "Previous crises"/*
*/ 		viol2 "Violence level"/*
*/ 		crisdur2 "Crisis duration"/*
*/ 		jointdem "Democratic dyad"/*
*/ 		victory2 "Victory"/*
*/ 		contig2 "Contiguity"/*
*/ 		prevcris2_t "Previous crises * time"/*
*/ 		viol2_t "Violence level * time"/*
*/ 		crisdur2_t "Crisis duration * time"/*
*/ 		jointdem_t "Democratic dyad * time"/*
*/ 		victory2_t "Victory * time"/*
*/ 		contig2_t "Contiguity * time"/*
*/		_cons Constant)
esttab using _table1.rtf, star(* 0.1 ** 0.05 *** 0.01)  b(3) se(3)  mtitle nodepvar  /*
*/ 		order(manip2 manip2_t nomanip2 nomanip2_t) noobs replace /*
*/		scalar("N_sub Cases" "N_fail Failures") /*
*/ 		varlabels(manip2 "Manipulation"/*
*/ 		manip2_t "Manipulation * time"/*
*/		nomanip2 "Other mediation "/*
*/ 		nomanip2_t "Other mediation * time"/*
*/ 		prevcris2 "Previous crises"/*
*/ 		viol2 "Violence level"/*
*/ 		crisdur2 "Crisis duration"/*
*/ 		jointdem "Democratic dyad"/*
*/ 		victory2 "Victory"/*
*/ 		contig2 "Contiguity"/*
*/ 		prevcris2_t "Previous crises * time"/*
*/ 		viol2_t "Violence level * time"/*
*/ 		crisdur2_t "Crisis duration * time"/*
*/ 		jointdem_t "Democratic dyad * time"/*
*/ 		victory2_t "Victory * time"/*
*/ 		contig2_t "Contiguity * time"/*
*/		_cons Constant) nonotes  /*
*/ 		addnotes("cluster robust s.e., * p < 0.1, ** p < 0.05, *** p < 0.01") 
esttab using _table1.tex, star(* 0.1 ** 0.05 *** 0.01)  b(3) se(3) label  /*
*/ 		replace noobs scalar("N_sub Cases" "N_fail Failures") /*
*/ 		order(manip2 manip2_t nomanip2 nomanip2_t) /*
*/ 		varlabels(manip2 "Manipulation"/*
*/ 		manip2_t "Manipulation * time"/*
*/		nomanip2 "Other mediation "/*
*/ 		nomanip2_t "Other mediation * time"/*
*/ 		prevcris2 "Previous crises"/*
*/ 		viol2 "Violence level"/*
*/ 		crisdur2 "Crisis duration"/*
*/ 		jointdem "Democratic dyad"/*
*/ 		victory2 "Victory"/*
*/ 		contig2 "Contiguity"/*
*/ 		prevcris2_t "Previous crises $\times$ time"/*
*/ 		viol2_t "Violence level $\times$ time"/*
*/ 		crisdur2_t "Crisis duration $\times$ time"/*
*/ 		jointdem_t "Democratic dyad $\times$ time"/*
*/ 		victory2_t "Victory $\times$ time"/*
*/ 		contig2_t "Contiguity $\times$ time"/*
*/		_cons Constant)  /*
*/ 		nodepvar mtitle nonotes booktabs /*
*/ 		addnotes("cluster robust s.e., * p \textless 0.1, ** p \textless 0.05, *** p \textless 0.01") 
